//
//  ClassViewController.m
//  Cat
//
//  Created by lushitong on 2018/12/31.
//  Copyright © 2018年 lushitong. All rights reserved.
//

#import "ClassViewController.h"
#import "HttpAssottManager.h"
#import "ClassCollectionView.h"
#import "GHDropMenu.h"
#import "GHDropMenuModel.h"

@interface ClassViewController ()<GHDropMenuDelegate>

@property (nonatomic, strong) ClassCollectionView *classCollectView;

@property (nonatomic , strong)GHDropMenu *dropMenu;

@end

@implementation ClassViewController

- (void)viewDidLoad {
    [super viewDidLoad];
	[self.topTitleView setDetailDic:@{Nav_Title:self.titileString}.mutableCopy];
	[self loadAllView];
}

- (void)loadAllView {
	[self.view addSubview:self.classCollectView];
	/** 配置筛选菜单模型 */
	GHDropMenuModel *configuration = [[GHDropMenuModel alloc]init];
	/** 配置筛选菜单是否记录用户选中 默认NO */
	configuration.recordSeleted = NO;
	/** 设置数据源 */
	configuration.titles = [configuration creaDropMenuData];
	/** 创建dropMenu 配置模型 && frame */
	WEAKSELF;
	GHDropMenu *dropMenu = [GHDropMenu creatDropMenuWithConfiguration:configuration frame:CGRectMake(0, self.topTitleView.bottom,kGHScreenWidth, kQKFitModuleDecimal(34.0)) dropMenuTitleBlock:^(GHDropMenuModel * _Nonnull dropMenuModel) {
		weakSelf.navigationItem.title = [NSString stringWithFormat:@"筛选结果: %@",dropMenuModel.title];
	} dropMenuTagArrayBlock:^(NSArray * _Nonnull tagArray) {
		
	}];
	
	dropMenu.titleSeletedColor = COLOR_WITH_HEX(0x4C4947);
	dropMenu.titleNormalColor = COLOR_WITH_HEX(0x756D68);
	dropMenu.optionFont = [UIFont systemFontOfSize:kQKFitFont(12)];
	dropMenu.optionSeletedColor = COLOR_WITH_HEX(0x4C4947);
	dropMenu.optionNormalColor = COLOR_WITH_HEX(0x756D68);
	dropMenu.titleNormalImageName = @"menu_arrow_up";
	dropMenu.titleSeletedImageName = @"menu_arrow_down";
	dropMenu.delegate = self;
	dropMenu.durationTime = 0.25;
	self.dropMenu = dropMenu;
	[self.view addSubview:dropMenu];
}

- (void)p_topLeftBtnClick {
	[super p_topLeftBtnClick];
	[self.dropMenu closeMenu];
}

#pragma mark----- lazy init -----

- (ClassCollectionView *)classCollectView  {
	if (!_classCollectView) {
		UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
		layout.minimumLineSpacing = 0.0;
		layout.minimumInteritemSpacing = kQKFitModuleFloor(10);
		_classCollectView = [[ClassCollectionView alloc] initWithFrame:CGRectMake(0.0, self.topTitleView.bottom + kQKFitModuleDecimal(34.0), ScreenWidth, ScreenHeight - self.topTitleView.height - kQKFitModuleDecimal(34.0)) layout:layout withProductID:self.productNumber];
		_classCollectView.backgroundColor = [UIColor whiteColor];
	}
	return _classCollectView;
}

#pragma mark - 代理回调

- (void)dropMenu:(GHDropMenu *)dropMenu dropMenuTitleModel:(GHDropMenuModel *)dropMenuTitleModel {
	NSString *type = @"01";
	/*
	 01是综合排序、
	 02是优惠券排序、
	 03是返佣排序、
	 04是券后价从高到低、
	 05是券后价从低到高、
	 06是销量从高到低、
	 07是销量从低到高
	 */
	if (dropMenuTitleModel.secIdentifier == 1) {
		if (dropMenuTitleModel.tagIdentifier == 0) {
			type = @"01";
		} else if (dropMenuTitleModel.tagIdentifier == 1) {
			type = @"02";
		} else {
			type = @"03";
		}
	} else if (dropMenuTitleModel.secIdentifier == 2) {
		if (dropMenuTitleModel.tagIdentifier == 0) {
			type = @"04";
		} else {
			type = @"05";
		}
	} else {
		if (dropMenuTitleModel.tagIdentifier == 2) {
			type = @"06";
		} else {
			type = @"07";
		}
	}
	[self.classCollectView sendRequestWithIndexType:type];
}

@end
